package com.changgou.order.service.impl;

import com.changgou.order.dao.RemindCountMapper;
import com.changgou.order.pojo.RemindCount;
import com.changgou.order.service.RemindCountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:RemindCount业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class RemindCountServiceImpl implements RemindCountService {

    @Autowired
    private RemindCountMapper remindCountMapper;


    /**
     * RemindCount条件+分页查询
     * @param remindCount 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<RemindCount> findPage(RemindCount remindCount, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(remindCount);
        //执行搜索
        return new PageInfo<RemindCount>(remindCountMapper.selectByExample(example));
    }

    /**
     * RemindCount分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<RemindCount> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<RemindCount>(remindCountMapper.selectAll());
    }

    /**
     * RemindCount条件查询
     * @param remindCount
     * @return
     */
    @Override
    public List<RemindCount> findList(RemindCount remindCount){
        //构建查询条件
        Example example = createExample(remindCount);
        //根据构建的条件查询数据
        return remindCountMapper.selectByExample(example);
    }


    /**
     * RemindCount构建查询对象
     * @param remindCount
     * @return
     */
    public Example createExample(RemindCount remindCount){
        Example example=new Example(RemindCount.class);
        Example.Criteria criteria = example.createCriteria();
        if(remindCount!=null){
            // 订单id
            if(!StringUtils.isEmpty(remindCount.getOrderId())){
                    criteria.andEqualTo("orderId",remindCount.getOrderId());
            }
            // 订单创建时间
            if(!StringUtils.isEmpty(remindCount.getRemindTime())){
                    criteria.andEqualTo("remindTime",remindCount.getRemindTime());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(String id){
        remindCountMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改RemindCount
     * @param remindCount
     */
    @Override
    public void update(RemindCount remindCount){
        remindCountMapper.updateByPrimaryKey(remindCount);
    }

    /**
     * 增加RemindCount
     * @param remindCount
     */
    @Override
    public void add(RemindCount remindCount){
        remindCountMapper.insert(remindCount);
    }

    /**
     * 根据ID查询RemindCount
     * @param id
     * @return
     */
    @Override
    public RemindCount findById(String id){
        return  remindCountMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询RemindCount全部数据
     * @return
     */
    @Override
    public List<RemindCount> findAll() {
        return remindCountMapper.selectAll();
    }
}
